package com.sds.sweng.swat.miplatform.ui.design.parts.area.sub;

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.EditPolicy;

import com.sds.sweng.swat.miplatform.ui.design.models.area.sub.SubArea;
import com.sds.sweng.swat.miplatform.ui.design.parts.MiplatformContainerPart;
import com.sds.sweng.swat.miplatform.ui.design.policies.SubAreaLayoutEditPolicy;
import com.sds.sweng.swat.miplatform.ui.design.utils.FontUtils;

public abstract class SubAreaPart extends MiplatformContainerPart {

	public boolean isSelectable() {
		return true;
	}

	protected IFigure createFigure() {
		Label f = new Label(((SubArea) getModel()).getName());
		f.setBorder(new LineBorder());
		f.setLabelAlignment(PositionConstants.CENTER);
		f.setFont(FontUtils.DEFAULT_FONT);

		int subAreaWidth = getAreaWidth();
		f.setSize(subAreaWidth, SubArea.MODEL_HEIGHT);

		((SubArea) getModel()).setWidth(getContentsWidth());

		return f;
	}

	protected void clearChildren(IFigure parent) {
		List<IFigure> children = parent.getChildren();
		for (int i=children.size()-1;i>-1;i--) {
			parent.remove(children.get(i));
		}
	}

	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new SubAreaLayoutEditPolicy());
	}

}
